<template>
  <!-- <div class="icons">
    <div v-for="item of icons" class="icon">
      <div class="icon-img">
        <img class="icon-img-content" :src="item.imgSrc"  alt="">
      </div>
      <p class="icon-data">{{item.data}}</p>
    </div>
  </div> -->
<div class="icons">
  <swiper :options="swiperOption" >
    <swiper-slide v-for="page of pages" :key="page.id">
        <div v-for="item of page" :key="item.id" class="icon">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl"  alt="">
          </div>
          <p class="icon-data">{{item.desc}}</p>
        </div>
    </swiper-slide>
    <!-- Optional controls -->
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
</div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        grabCursor: true,
        setWrapperSize: true,
        pagination: '.swiper-pagination',
        paginationClickable: true,
        mousewheelControl: true,
        observeParents: true,
        // if you need use plugins in the swiper, you can config in here like this
        // 如果自行设计了插件，那么插件的一些配置相关参数，也应该出现在这个对象中，如下debugger
        debugger: true
        // swiper callbacks
        // swiper的各种回调函数也可以出现在这个对象中，和swiper官方一样
        // onTransitionStart (swiper) {
        //   console.log(swiper)
      // }
      }
    }
  },
  // 通过计算属性将图标分页
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/mixins.styl'
@import '~styles/varibles.styl'
  >>>.swiper-pagination-bullet
    width: 6px;
    height: 6px;
  >>>.swiper-pagination-bullet-active
        background:$bgColor !important
  .icons
    margin-top: .2rem;
    overflow: hidden
    height: 0
    padding-bottom: 55%
    .icon
      overflow: hidden;
      float: left
      width: 25%
      height: 0;
      padding-bottom: 25%
      background: #fff
      position: relative;
      .icon-img
        width: 65%;
        margin: auto;
        .icon-img-content
          width: 100%;
      .icon-data
          margin-top: 0.2rem
          font-weight: 600;
          text-align: center;
          ellipsis()
  .swiper-pagination
        position: absolute;
        margin: auto;
        bottom: 0
</style>
